/*
 * This file (AxPromptLogListener.java) is protected by the GNU GPL licence (v2). 
 * Please read the license.txt attached for further informations. 
 * 
 */

package artx.listeners;

import javax.swing.JOptionPane;

import artx.events.AxLogEvent;
import artx.utils.AxConstants;

/**
 * All new messages are displayed using a graphic dialog. Only used as an
 * exemple, as this can get pretty boring (if your in debug level).
 * 
 * @author Xavier Gouchet
 * 
 */
public class AxPromptLogListener implements AxLogListener, AxConstants {

	private int level;

	/**
	 * Standard constructor
	 * 
	 * @param lvl
	 *            the prompt level mode
	 */
	public AxPromptLogListener(int lvl) {
		this.level = lvl;
	}

	/**
	 * 
	 * @see artx.listeners.AxLogListener#messageRegistered(artx.events.AxLogEvent)
	 */
	public void messageRegistered(AxLogEvent e) {
		int dlgtype;
		String type;
		if (this.level < e.GetLevel())
			return;

		switch (e.GetLevel()) {
		case LVL_ERROR:
			dlgtype = JOptionPane.ERROR_MESSAGE;
			type = "Error";
			break;
		case LVL_WARNING:
			dlgtype = JOptionPane.WARNING_MESSAGE;
			type = "Warning";
			break;
		case LVL_INFO:
			dlgtype = JOptionPane.INFORMATION_MESSAGE;
			type = "Info";
			break;
		default:
			dlgtype = JOptionPane.PLAIN_MESSAGE;
			type = "Message";
			break;
		}
		JOptionPane.showMessageDialog(null, e.GetMessage(), TITLE + " - "
				+ type, dlgtype);
	}

	/**
	 * @see artx.listeners.AxLogListener#debugMessageRegistered(artx.events.AxLogEvent)
	 */
	public void debugMessageRegistered(AxLogEvent e) {
		if (this.level < LVL_DEBUG)
			return;
		JOptionPane.showMessageDialog(null, e.GetMessage(), TITLE
				+ " - Debug Log", JOptionPane.PLAIN_MESSAGE);
	}

}
